package com.myprocessing.timer;

import com.myprocessing.action.MethodAction;

public class WhileTimer extends Timer {
	
	private MethodAction timerStop;
	
	public void init(){
		super.init();
		timerStop.init();
	}
	
	public void trigger() {
		super.trigger();
		executeAction(timerBegin);
	}
	
	public void update(long currentTime) {
		
		if (currentTime > begin && lastCheck < begin) {
			executeAction(timerBegin);
		}
		else if (!((Boolean)timerStop.executeMethodReturn()).booleanValue()){// && lastCheck < end) {
			active = false;
			executeAction(timerEnd);
		}
		
		if (active && (currentTime > begin) && (currentTime >= lastInterval + interval)) {
			executeAction(timerInterval);
			lastInterval = currentTime;
		}
		lastCheck = currentTime;
	}

	public MethodAction getTimerStop() {
		return timerStop;
	}

	public void setTimerStop(MethodAction timerStop) {
		this.timerStop = timerStop;
	}

}
